﻿using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text.RegularExpressions;
using System.Web;

namespace yMethod
{
    public class FuncHelp
    {
        /// <summary>
        /// 深拷贝
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static T DeepCopy<T>(T obj)
        {
            object retval;
            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(ms, obj);
                ms.Seek(0, SeekOrigin.Begin);
                retval = bf.Deserialize(ms);
                ms.Close();
            }
            return (T)retval;
        }


        public static bool IsNumberic(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return false;
            }
            //整数
            string pattern = @"^\-?\d*$";
            //浮点数
            string patternF = @"^-?\d+(\.\d*)$";

            return Regex.IsMatch(text, pattern) ? true : Regex.IsMatch(text, patternF);
        }
    }
}
